package com.enjoyor.soa.traffic.rest.efoms.dubbo.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.enjoyor.soa.traffic.api.dto.efoms.CheckDeviceInfoDto;
import com.enjoyor.soa.traffic.api.service.dubbo.efoms.IDubboCheckDeviceInfoService;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.ICheckDeviceInfoConsumeService;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.invoke.DubboLedProgInfoServiceInvoke;
import com.enjoyor.soa.traffic.rest.efoms.enums.EnumDicPublicRest;
import com.enjoyor.soa.traffic.rest.efoms.helper.CheckPojoHelper;
import com.enjoyor.soa.traffic.util.helper.MapHelper;
import com.enjoyor.soa.traffic.util.helper.ResultHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@Component
public class CheckDeviceInfoConsumeService implements ICheckDeviceInfoConsumeService{

	@Reference(version = "1.0.0", timeout = 10000)
	private IDubboCheckDeviceInfoService dubboCheckDeviceInfoService;

    @Autowired
    private DubboLedProgInfoServiceInvoke dubboLedProgInvoke;
	
	@Override
	public ResultPojo getCheckDeviceInfoPage(String DevId, String devTypeCode, String devName, String ledType,
			String devStatusCode, String isPingConnect, String checkResultCode, String devAreaCode, String isDelayData,
			String isHightPackage, String isHightResponse, String isHaveData, String devFactory, String searchFlag,String beginLastPassTime,String endLastPassTime,String isPhotoSuccess,String repStatusCode,String project,String company,
			String picStatusFlag,Page page) {
		// TODO Auto-generated method stub
		ResultPojo resultPojo = dubboCheckDeviceInfoService.getCheckDeviceInfoPage(DevId, devTypeCode, devName, ledType,
				devStatusCode, isPingConnect, checkResultCode, devAreaCode, isDelayData, isHightPackage,
				isHightResponse, isHaveData, devFactory, searchFlag,beginLastPassTime,endLastPassTime,isPhotoSuccess,repStatusCode,project,company,picStatusFlag,page);
		//诱导数据获取是否有当前节目
		if(null != devTypeCode && EnumDicPublicRest.INSCREEN.getKey().equals(devTypeCode)) {
			Page pageR = (Page)resultPojo.getResultList();
			if(pageR != null  && pageR.getResult() != null && pageR.getResult().size() > 0) {
				Map<String, Object> map = new HashMap<String, Object>();
				List<Map<String, Object>> checkDeviceMapList = (List<Map<String, Object>>)pageR.getResult();
				List<CheckDeviceInfoDto> resultList = new ArrayList<CheckDeviceInfoDto>();
				for(Map<String, Object> checkDeviceMap : checkDeviceMapList) {
					CheckDeviceInfoDto checkDeviceInfoDto = MapHelper.map2Bean(checkDeviceMap, CheckDeviceInfoDto.class);
					String ledId = checkDeviceInfoDto.getDevId();
					boolean isLedProgram = dubboLedProgInvoke.getIsLedProgram(ledId);
					checkDeviceInfoDto.setIsLedProgram(isLedProgram);
					resultList.add(checkDeviceInfoDto);
				}
				pageR.setResult(resultList);
				resultPojo =  ResultHelper.getResult(pageR);
			}
		}
		return resultPojo;
	}

	@Override
	public ResultPojo getCheckDeviceInfoList(String DevId, String devTypeCode, String devName, String ledType,
			String devStatusCode, String isPingConnect, String checkResultCode, String devAreaCode, String isDelayData,
			String isHightPackage, String isHightResponse, String isHaveData, String devFactory, String searchFlag) {
		// TODO Auto-generated method stub
		return dubboCheckDeviceInfoService.getCheckDeviceInfoList(DevId, devTypeCode, devName, ledType, devStatusCode,
				isPingConnect, checkResultCode, devAreaCode, isDelayData, isHightPackage, isHightResponse, isHaveData,
				devFactory, searchFlag);
	}

	@Override
	public ResultPojo getCheckDeviceInfo(String DevId) {
		// TODO Auto-generated method stub
		return dubboCheckDeviceInfoService.getCheckDeviceInfo(DevId);
	}

	@Override
	public ResultPojo getCheckCount(String beginTime, String endTime,String devTypeCode) {
		// TODO Auto-generated method stub
		return dubboCheckDeviceInfoService.getCheckCount(beginTime, endTime,devTypeCode);
	}

	@Override
	public ResultPojo reFreshCheckResult(String devTypeCode) {
		// TODO Auto-generated method stub
		return dubboCheckDeviceInfoService.reFreshCheckResult(devTypeCode, null);
	}

}
